
<?=$this->headTitle($this->escape($this->item['title']));?>
<?=$this->headMeta()->appendHttpEquiv('Content-Type','text/html; charset=UTF-8')
                    ->appendHttpEquiv('Content-Language', 'ru-RU');?>

<?php if(!empty($this->item)):?>
    <link href='js/jRating/jRating.jquery.css' type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" href="js//highslide/highslide.css" />
<?=$this->JQuery()
	->addStylesheet('js/wysibb/theme/default/wbbtheme.css')
	->addJavaScriptFile($this->baseUrl('js/wysibb/jquery.wysibb.js'))
	->addJavaScriptFile($this->baseUrl('js/wysibb/script.js'))
;?>
    <script src='js/jRating/jRating.jquery.js' type="text/javascript" language="javascript"></script>
    <script src='js/highslide/highslide-with-gallery.js' type="text/javascript" language="javascript"></script>
    <script type="text/javascript" src="//vk.com/js/api/openapi.js?98"></script>
    <script type="text/javascript">
        VK.init({apiId: 3793483, onlyWidgets: true});
    </script>
	<script type="text/javascript">
$('body').data('key',false);
$('body').data('repeat',false);
$('body').data('article_id',false);
$(function(){

    hs.graphicsDir = 'js/highslide/graphics/';
    hs.align = 'center';
    hs.transitions = ['expand', 'crossfade'];
    hs.outlineType = 'rounded-white';
    hs.wrapperClassName = 'controls-in-heading';
    hs.fadeInOut = true;
    //hs.dimmingOpacity = 0.75;

    // Add the controlbar
    if (hs.addSlideshow) hs.addSlideshow({
        //slideshowGroup: 'group1',
        interval: 5000,
        repeat: false,
        useControls: true,
        fixedControls: false,
        overlayOptions: {
            opacity: 1,
            position: 'top right',
            hideOnMouseOut: false
        }
    });

var imgZoom = $('p a.highslide');
    if(imgZoom.length > 1 && imgZoom.find('img').width() > 200){
        imgZoom.each(function(i,e){
            $(e).attr({'onclick':'return hs.expand(this)'});
        });
    }else if(imgZoom.length ===1 && imgZoom.find('img').width() > 200){
        imgZoom.attr({'onclick':'return hs.expand(this)'});
    }
var aid =$('#article_id').val();
$('body').data('article_id',aid);
articleRatingFirstLoad();

var slideD = $('#content').height()-$('#comments').height()-$('.comments-list').height();

$('form#comments').attr('onsubmit','return checkform(this)').hide().find('#comSubmit').hover(function(){$(this).focus();});
$('span.powered').remove();
var button = $('<button>',{'text':'Добавить комментарий','title':'Добавить комментарий','id':'commentButton','align':'center'});
$('#commentsform').append(button);
button.click(function(){

		$('form#comments').slideDown('slow');
		$('html,body').animate({scrollTop: slideD}, 'slow');
		button.hide();
});
	$('form#comments input, div.wysibb-text-editor').blur(function(){
		if($(this).attr('class')==='wysibb-text-editor wysibb-body'){
            check($(this));
        }else{

            var formElm = $(this).parent().children('input').not('#comSubmit');

            check(formElm);
        }

		});
		
	$('span#link').click(function()
	{
	var	count = $("#captcha-element").parent().find('#captcha-element img');
	if(count.length >1)
	{
		$("#captcha-element img:last-child").remove();
	}	
	$.ajax({
			type:'POST',
			url: '/users/index/refresh',
			success: function(data) {
                $('#captcha-element img').attr('src',data.src);
                $('#captcha-id').attr('value',data.id);
            }
			});
	});
});
function articleRatingFirstLoad()
{
var articleRating = {'articleid':$('#article_id').val()};
$.ajax({
	type:'POST',
	dataType:'json',
	data:articleRating,
	url:'catalog/item/rating',
	error: function(){ disabling()},
	success:function(resp){request(resp)}
});
}

function disabling(){
  $('.basic').jRating({
        rateMax:5,
        step:true,
        isDisabled:$('body').data('repeat'),
        onSuccess:function(obj,rate){
                if($('body').data('repeat')===false){
                    articleRatingFirstLoad();
                }
            }
        });
}

function request(resp){
			if(resp.article_score===0 && resp.article_votes===0)
			{
			$('#art_rating').append('<p style="font-size:12px;display:block;clear:both;padding-bottom:20px;border-bottom:1px solid #BBBBBB">Средняя оценка статьи: '+0+'</p>');
			$('body').data('repeat',false);
			disabling();
			}
			if(resp.article_score !==0 && resp.repeat===true)
			{
			$('#art_rating').replaceWith('<p style="font-size:12px;display:block;clear:both;padding-bottom:20px;border-bottom:1px solid #BBBBBB">Средняя оценка статьи: <strong>'+(resp.article_score/resp.article_votes).toFixed(2)+'</strong> / Всего голосов: '+resp.article_votes+' </p>');
			$('body').data('repeat',true);
			disabling();
			
			}
			else if(resp.article_score !==0 && resp.repeat===false)
			{
			$('#art_rating').append('<p style="font-size:12px;display:block;clear:both;padding-bottom:20px;border-bottom:1px solid #BBBBBB">Средняя оценка статьи: <strong>'+(resp.article_score/resp.article_votes).toFixed(2)+'</strong> / Всего голосов: '+resp.article_votes+' </p>');
			$('body').data('repeat',false);
			disabling();
			}
		$('#rating').css('height','44');
	}

function check(elm){

    var inp = {},id;
    if(elm.length > 1){
        var eLen = elm.length;
        for(var i=0;i<eLen;i+=1){
              inp[$(elm[i]).attr('name')] = $(elm[i]).val();
        }
        id = 'captcha';
    }else{
         id=elm.attr('id') || elm.parent().find('textarea').attr('id');


	var formComm = $('form#comments :input');
      formComm.each(function(i,el){

          if($(el).attr('class') ==='wysibb-texarea'){
              inp[$(el).attr('name')]=$(el).parent().find('.wysibb-text-editor').text();
          }else{
              inp[$(el).attr('name')]=$(el).val();
          }
      });
    }
		$.ajax({
				type:'POST',
				url:'catalog/item/validate/format/json',
				dataType:'json',
				data:inp,
				success:function(resp){
                                    if(resp.email || resp.username || resp.blog_comment || resp.captcha){
                                        $('body').data('key',false);
                                        errors(id,resp[id]);

                                    }else{$('body').data('key',true);}
                                        $('#'+id).parent().append($('<ul>',{'class':'errors'}));
                                        errors(id,resp[id]);
                                    }
                });
}
function errors(id,msg){
    setTimeout(function(){$('#comSubmit').removeAttr('disabled');},3000);
var elm,img, m,ul_li, w,ms,ul_errors,e;
    elm = $('form#comments input#'+id);
	if(id && msg){

        if(id === 'captcha'){elm = $('form#comments input#'+id+'-input');$('#link-element').css('margin-top','-13px');}
		if(id !=='blog_comment'){


            img = elm.parent().find('img.ok');
            if(img.length > 0){img.remove();}
			    if(elm.parent().find('ul li').length >0){
                    elm.parent().find('ul').remove();
                }
			    for( m in msg){
                    console.log(id);
                        elm.parent().css('margin-bottom','0').append('<ul class="errors"><li>'+msg[m]+'</li></ul>');
                }
	    }else{
			if(id ==='blog_comment'){
				 ul_li = $('.wysibb').parent().find('ul li');
                    if(ul_li.length >0){ul_li.remove();}
                        w = $('.comments').children('.wysibb');
				        for( ms in msg){
                            w.parent().css('margin-bottom','0').append('<ul class="errors"><li>'+msg[ms]+'</li></ul>');
					    }
			}
		}
	}else{
         if(id === 'captcha'){elm = $('form#comments input#'+id+'-input');$('#link-element').css('margin-top','-13px');}
			if(id !=='article_id'){
                img = elm.parent().find('img.ok');
					if(img.length >0){img.remove();}
						ul_errors = elm.parent().find('ul.errors');
						    if(ul_errors.length >0){ul_errors.remove();}
							    if(id ==='blog_comment'){
								    $('.wysibb').parent().css('margin-bottom','13px').find('ul li').remove();return;
								}
				elm.parent().css('margin-bottom','13px').append($('<img>',{'class':'ok','src':'images/ok.png'}).css('padding-left','5px'));
			}
        }
}
function checkform(form){
    $('#comSubmit').attr('disabled','disabled');
var data={};
var art = $('#article').height();

    $(form.elements).not('#comSubmit').each(function(){

        if($(this).attr('class') ==='wysibb-text-editor'){
            data[$(this).parent().find('textarea').attr('name')]=$(this).text();
        }else{
            data[$(this).attr('name')]=$(this).val();
        }
    });

    $.ajax({
        type:'POST',
        url:'catalog/item/validate/format/json',
        data:	data,
        dataType:'json',
        success:function(res){

            for(var id in res){
                if(id !=='menu'){
                    errors(id,res[id]);
                }
            }
        }
    });

var showForm = function(){
	$('#message').remove();
	$('form#comments input,div.wysibb-text-editor').not('#comSubmit').each(function()
		{
			if($(this).attr('class')==='wysibb-text-editor wysibb-body'){$(this).text('');}
			$(this).val('');
			$(this).parent().not('#captcha-element').find('img').remove();
		});
	$('span#link').click();
		
	$('#commentButton').show('fade');
    $('#comSubmit').removeAttr('disabled');
}
var key = $('body').data('key');

  if(key===true){
    if(!data.article_id){
        data.article_id = $('body').data('article_id');
    }
	$.ajax({
		type:'POST',
		url:'catalog/item/display',
		data:	data,
		dataType:'json',
        error:function(){
            $('form#comments').hide('fast');
            $('#commentsform').append('<div id="message" class="alert alert-error" style="text-align:center;width:600px; height:20px; top:25px;">Ошибка отправки комментария, повторите отправку позже</div>');
            setTimeout(showForm,6000);
        },
		success:function(res){
			if(res.status !=='XHR'){
                $('form#comments').slideUp();
                $('#commentsform').append('<div id="message" class="alert alert-error" style="text-align:center;width:600px; height:20px; top:25px;">Ошибка отправки комментария, повторите отправку снова</div>');
                setTimeout(showForm,6000);
			}
		}
	});
      $('form#comments').slideUp('slow');
      $('#commentsform').append('<div id="message" class="alert alert-success" style="width:600px; height:20px; top:25px;">Ваш комментарий будет опубликован после проверки модератором</div>');//<p id="message" style="width:600px; height:71px; top:25px;">
      setTimeout(showForm,3000);
		return false;
  }
return key;
}
</script>
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/ru_RU/all.js#xfbml=1&appId=169190319930871";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>
<br/>
<div align="center">
    <h2 style="padding:0;margin:0;color:#333333;text-align:left;font-family:Ubuntu"><?=$this->escape($this->escape($this->item['title']));?></h2>
    <div class="publish" style="display:block;clear:both;text-align:left;">

        <img src="images/user.png" title="Выложил статью" style="vertical-align: middle"/><span class="author" title="автор статьи"><?=$this->escape($this->item['author']);?></span>|
        <span class="category">Категория: <?=$this->escape($this->item['category_name']);?></span>|
       <time class="created_time" title="Дата создания"><i class="icon-time"></i> <?=$this->escape($this->item['created_dt']);?></time>
    </div>
</div>
    <div class="footer" style="border:none;">

    </div>

<div class="article"><?=$this->item['article'];?>

    <div  class="g-plusone" data-annotation="inline" data-width="300" href="http://www.itdocs.kz"></div>
    <script type="text/javascript">
        (function() {
            window.___gcfg = {
                lang: 'ru',
                parsetags: 'onload'
            };
            var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
            po.src = 'https://apis.google.com/js/plusone.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
        })();
    </script>

    <div id="vk_like"></div>
    <script type="text/javascript">
        VK.Widgets.Like("vk_like", {type: "button"});
    </script>
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="ru">Твитнуть</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<a target="_blank" class="mrc__plugin_uber_like_button" href="http://connect.mail.ru/share" data-mrc-config="{'cm' : '1', 'sz' : '20', 'st' : '2', 'tp' : 'mm'}">Нравится</a>
<script src="http://cdn.connect.mail.ru/js/loader.js" type="text/javascript" charset="UTF-8"></script>
<div class="fb-like" data-href="http://developers.facebook.com/docs/reference/plugins/like" data-send="true" data-width="450" data-show-faces="true" href="http://itdocs.kz/catalog/item/diasplay/164"></div>

</div>
<br/>
<div id="rating" style="font-size:12px;color:#555555;">
	<div style="float:left;padding-right:10px">Проголосуйте за статью</div>
	<div class="basic"  data-average="<?=$this->escape($this->rating);?>" data-id="1" style="float:left;"></div><br/>
	<div id="art_rating" style="height:15px;padding:0"></div>
</div>

<h5 style="padding-top:40px;clear:both"><?=$this->escape($this->title);?></h5>

<?php if(isset($this->label)):?>
<ul class="similar-articles">
<?php foreach($this->label as $l):?>
<li class="similar-articles"><h5><a href="<?=$this->url(array('id'=>$l['article_id']),'catalog-display')?>" title="Похожие статьи"><?=$this->escape($l['title']);?></a></h5></li>
<?php endforeach;?>
<?php endif;?>
</ul>

<div id="commentsform"></div>
<?=$this->comments;?>

<?php if(!empty($this->permit_comments)):?>
<p style="font-size:14px;">Всего комментариев (<?=$this->commcount?>)</p>
<ul class="comments-list">
<?php foreach($this->permit_comments as $pc):?>
	<li>
		<h5>
	<a href="<?=$pc['avatar'];?>"><img src="<?=$pc['avatar'];?>"></a>&nbsp<span style="color:#DDD;" >
	<?=$this->escape($pc['role']);?></span>&nbsp&nbsp<?=$this->escape($pc['name']);?>&nbsp<span style="font: italic 10px serif; color:#555555">(<?=$this->escape($pc['created_dt']);?>)
		</h5>

	<p><?=$this->bb->render($this->escape($pc['blog_comment']));?></p>
</li>
<?php endforeach;?>
</ul>
<?php else:?>
        <p style="padding-left:220px">Комментариев нет</p>
<?php endif;?>


<?php else:?>
<p>Статьи не существует</p>
<?php endif;?>
